<!DOCTYPE html>
<html>
<head>
<title>template</title>
<meta name="keywords" charset=utf-8/>
<!--[if !IE]> -->
  <script src="http://cdn.bootcss.com/jquery/2.2.0/jquery.min.js"></script>
  <!-- <![endif]-->
  <!--[if IE]>
      <script src="http://cdn.bootcss.com/jquery/1.12.0/jquery.js"></script>
  <![endif]-->
<style>
*{
  margin:0;
  padding:0;
}
    .wrap{width:500px;height:auto;}
    .f_l{float:left;width:200px;}
    .abox{width:100%;height:300px;}
    .bbox{width:100%;height:200px;margin-top:15px;}
    .f_r{float:right;width:260px;}


</style>
</head>
<body>
<!--   <ul id="testUL">
    <li> index = 0</li>
    <li> index = 1</li>
    <li> index = 2</li>
    <li> index = 3</li>
</ul> -->
<div class="wrap">
    <div class="f_l">
        <div class="abox"></div>
        <div class="bbox"></div>
    </div>
    <div class="f_r"></div>
</div>


<script>
var str="hello-world";
console.log(str);
var a=str.split("-");
for (var i = 0; i < a.length; i++) {
	a[i] = a[i].charAt(0).toUpperCase()+a[i].slice(1);
};
var b = a.join(" ");
console.log(b);

//数组排序
var arr_a = [4,7,45,6,2,16];
console.log(arr_a);
console.log(arr_a.sort());
console.log(arr_a.sort(function(a,b){return a-b}));
console.log(arr_a.sort(function(a,b){return b-a}));

//点击输出index
var nodes = document.getElementsByTagName("li");
for (var i = 0; i < nodes.length; i++) {
	var a=i;
	nodes[i].onclick=(function(a){
		return function(){
			alert(a);
		}
	})(i);
};

//打印日期2014-09-26
var dt = new Date()
console.log(dt);
var year = dt.getFullYear();
var month = dt.getMonth()+1;
month = (month<10)?"0"+month:month;
var day = dt.getDate();
day = (day<10)?"0"+day:day;
var dt_final = year+"-"+month+"-"+day;
console.log(dt_final);

//随机数10-100
function randomNumber(start,end){
	var a = (end-start)+1;
	var radomNumber = parseInt(Math.random()*a) + start;
	return radomNumber;
}
var randomArr = [];
for (var i = 0; i < 10; i++) {
	randomArr[i] = randomNumber(10,100);
};
console.log(randomArr);

//闭包
for(var i=1;i<=3;i++){
    setTimeout((function(a){  
    //改成立即执行函数
       console.log(a);    
    })(i),0);  
  };

//斐波那契数列

var result=[];
  function fn(n){  
  //典型的斐波那契数列
     if(n==1){
          return 1;
     }else if(n==2){
             return 1;
     }else{
          if(result[n]){
                  return result[n];
          }else{
                  
              //argument.callee()表示fn()
              result[n]=arguments.callee(n-1)+arguments.callee(n-2);
              console.log(result);
              return result[n];
          }
     }
  }
console.log(fn(10));

//给string添加一个方法使得addSpace("hello world") // -> 'h e l l o  w o r l d'
String.prototype.addSpace=function(){
	return this.split("").join("  ");	
}
var str="hello world";
console.log(str.addSpace());

//数组去重
function arrUnique(array){
	var a = {};
	var b = [];
	for (var i = 0; i < array.length; i++) {
		if(!a[array[i]]){
			a[array[i]] = 1;
			b.push(array[i]);
		}else{
			a[array[i]] += 1;
		}

	};
	return b;
}
var array2 = [12,78,2,8,2,6,12];
console.log(array2);
var array3 = arrUnique(array2);
console.log(array3);

//深复制或者说复制对象
//先判断变量是什么类型的
function isClass(o){
	if(o===null){
		return null;
	}else if(o===undefined){
		return undefined;
	}else{
		return Object.prototype.toString.call(o).slice(8,-1);
	}
}
var o1="123";
var o2=[23,78,9];
var o3={"name":"zlp","sex":"female"};

function deepClone(o){
	var res;
	var isclass = isClass(o);
	if(isclass==="Array"){
		res = [];
	}else if(isclass==="Object"){
		res={};
	}else{
		return o;
	}
	for(var key in o){
		var copy = o[key];
		if(isClass(copy)==="Array"){
			 res[key]=arguments.callee(copy);
		}else if(isClass(copy)==="Object"){
			 res[key]=arguments.callee(copy);
		}else{
			 res[key] = o[key];
		}

	}
	return res
}
// console.log(deepClone(o1));
console.log(deepClone(o2));
console.log(deepClone(o3));

//一个方法获取到非行间样式

// var temp;
// alert(typeof(temp));

</script>
</body>
</html>